var api = require('../../utils/api.js')

Page({
    data: {
        list: [],
        userinfo:''
    },
    onLoad() {
        api.post({
            url: 'video/usergroup',
            data: {},
            success: data => {
                console.log(data);
                
            }
        });
    },
    onShow() {
        
        this.getuserinfo();

    },

    getuserinfo(){
        var that=this;
        api.post({
            url: 'user/index',
            data: {},
            success: data => {
                console.log(data);
                that.setData({
                    userinfo:data.data
                })
            }
        });
    },

    goout(){
        wx.setStorageSync('token', '');
        wx.setStorageSync('userinfo', '');

        wx.redirectTo({
          url: '/pages/login/login',
        })

    },

    onChooseAvatar(ret){
        console.log(ret);

        var file=ret.detail.avatarUrl;
        var that=this;
        var uid=this.data.userinfo.id;

        var usrl=api.HOST;
        wx.uploadFile({
            filePath: file,
            name: 'file',
            url: usrl+'/api/demo/upload?uid='+uid,
            formData:{},
            success:function(res){
              var data= JSON.parse(res.data);
              
              that.getuserinfo();
            },
            fail: function (res) {
              console.log('上传失败');
              }
          })

    },

    getimgs(){
        let that = this;
        var usrl=api.HOST;

        wx.uploadFile({
            filePath: tempFilePaths[0],
            name: 'file',
            url: usrl+'/api.php?s=portal/index/one',
            formData:{},
            success:function(res){
              var data= JSON.parse(res.data);
              that.setData({
                imgs:data.data.img
              });
      
            },
            fail: function (res) {
              console.log('上传失败');
              }
          })
    },

    
});